package com.ocm.tourism.file;

public class MimeTypeSupport {

   public static final String PNG_MINETYPE = "image/png";

   public static final String JPEG_MINETYPE = "image/jpeg";

   public static final String GIF_MINETYPE = "image/gif";

   public static final String BMP_MINETYPE = "image/bmp";

   public static final String[] mineTypes = new String[] { PNG_MINETYPE, JPEG_MINETYPE, GIF_MINETYPE, BMP_MINETYPE };

   public static String convertFormatName(String mimeType) throws Exception {
      if (PNG_MINETYPE.equalsIgnoreCase(mimeType))
         return "png";

      if (JPEG_MINETYPE.equalsIgnoreCase(mimeType))
         return "jpg";

      if (GIF_MINETYPE.equalsIgnoreCase(mimeType))
         return "gif";

      if (BMP_MINETYPE.equalsIgnoreCase(mimeType))
         return "bmp";

      throw new Exception("Not support mineType: " + mimeType);
   }

   public static boolean supportMineType(String mineType) {
      for (String expectedMineType : mineTypes) {
         if (expectedMineType.equalsIgnoreCase(mineType)) {
            return true;
         }
      }
      return false;
   }
}
